package com.huanf.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.huanf.domain.ReadToMySQLVo;
import com.huanf.domain.WriterToExcelVo;
import com.huanf.service.WriterToExcelService;
import com.huanf.utils.ReadExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;

/**
 * @author: 35238
 * 功能: easyExcel-把数据库的数据写入到Excel表格
 * 时间: 2023-12-27 14:14
 */
@RestController
@Slf4j
public class ReadToMySQLController {

    @Autowired
    private WriterToExcelService writerToExcelService;

    @GetMapping("/readToMySQL") //浏览器访问 http://localhost:8082/readToMySQL
    public void image() throws Exception {

        //要读取Excel在哪个位置
        String PATH = "E:\\桌面\\Java-Ready\\conf\\Excel\\easyExcelWrite.xlsx";

        //读取Excel的数据。ReadExcelUtil是我们写的工具类，里面已经包含插入数据到数据库的操作了
        EasyExcel.read(PATH, ReadToMySQLVo.class, new ReadExcelUtil()).sheet().doRead();
    }

}
